SubProcessActivitySetting = function (editor) {
    this.editor = editor;
    this.setting = this.getCurrentAttributeSetting("subProcess");
};

mxUtils.extend(SubProcessActivitySetting, AttributeSetting);


/**
 * 渲染子流程活动属性配置页面
 */
SubProcessActivitySetting.prototype.renderSubProcessActSetting = function () {
    this.renderExtra();
    this.renderParametersOfSubProcessActivity();
};


/**
 * 渲染子流程活动WPE04其中一个tab 基本属性设置页面
 */
SubProcessActivitySetting.prototype.renderBasicAttrOfSubProcessActivity = function () {
    var basicAttrRegion = $('#ef_region_basicAttr');
    $('#name', basicAttrRegion)
        .attr('value', this.setting.getAttribute('Name'));
    $('#displayName', basicAttrRegion)
        .attr('value', this.setting.getAttribute('DisplayName'));
    var subProcessName = this.setting.getAttribute('SubProcessName');
    var subProcessDisplayName = this.setting.getAttribute('SubProcessDisplayName');
    /*treeinput解析到前台有两个input框，此刻的回显需要赋值给另一个隐藏的input*/
    document.getElementById('in-0-subProcessName').value = subProcessName;
    document.getElementById('in-0-subProcessName_textField').value = subProcessDisplayName;
    var instType = this.setting.getAttribute('InstType');
    if (instType == null) instType = "singleInst";
    $('#instTypeHide').attr('value', instType);
    var sumCsign = this.setting.getAttribute('SumCsign');
    if (sumCsign == null) sumCsign = "Y";
    $('#sumCsignHide').attr('value', sumCsign);
    document.getElementById('description').value = this.setting.getAttribute('Description');
};

/**
 * 渲染EWPE04其中一个tab 扩展属性数据表格
 *
 * @return
 */
SubProcessActivitySetting.prototype.renderExtra = function () {
    var extraGrid = $("#ef_grid_extraResult").data("kendoGrid");
    var dom = $(this.setting);
    var block = new Array();

    /*构造对应grid的对象*/
    function extraResult(Name, Type, Value, Desc) {
        this.Name = Name;
        this.Type = Type;
        this.Value = Value;
        this.Desc = Desc;
    }

    // 加载扩展属性数据
    $(dom).find('Variable').each(function () {
        /*循环给对象赋值--回显*/
        var row = new extraResult();
        $.each(this.attributes, function (i, attrib) {
            row[this.name] = this.value;
        });
        block.push(row);
    });
    extraGrid.dataSource.data(block);

};
/**
 * 渲染子流程参数EWPE04 其中一个tab 相关参数数据表格
 *
 * @return
 */
SubProcessActivitySetting.prototype.renderParametersOfSubProcessActivity = function () {
    var parametersResultGrid = $("#ef_grid_parametersResult").data("kendoGrid");
    var dom = $(this.setting);
    var block = new Array();

    function parametersResult(Variable, SubVariable, Type) {
        this.Variable = Variable;
        this.SubVariable = SubVariable;
        this.Type = Type;
    }

    // 加载扩展属性数据
    $(dom).find('Parameter').each(function () {
        var row = new parametersResult();
        $.each(this.attributes, function (i, attrib) {
            row[this.name] = this.value;
        });
        // row.push(this.getAttribute("Variable"));
        // row.push(this.getAttribute("SubVariable"));
        // row.push(this.getAttribute("Type"));
        block.push(row);
    });
    parametersResultGrid.dataSource.data(block);

};

/**
 * 保存子流程活动属性设置
 */
SubProcessActivitySetting.prototype.updateSubProcessActSetting = function () {
    // 三个子标签页分别保存
    this.updateBasicAtrrOfSubProcessActSetting();
    this.updateExtra();
    this.updateParametersOfSubProcessActSetting();

    this.updateAttributeSetting();
};

/**
 * 保存子流程活动基本属性设置
 */
SubProcessActivitySetting.prototype.updateBasicAtrrOfSubProcessActSetting = function () {
    // 获取活动属性配置
    var basicAttrRegion = $('#ef_region_basicAttr');
    var name = $("#name").val();
    var displayName = $("#displayName").val();
    var subProcessName = $("#in-0-subProcessName").val();
    var subProcessDisplayName = $("#in-0-subProcessName_textField").val();
    var instType = document.getElementById("instType").value;
    var sumCsign = document.getElementById("sumCsign").value;
    var description = $("#description").val();

    // 设置基本属性
    var cas = this.setting;
    cas.setAttribute('Name', name);
    cas.setAttribute('DisplayName', displayName);
    cas.setAttribute('Description', description);
    cas.setAttribute('SubProcessName', subProcessName);
    cas.setAttribute('SubProcessDisplayName', subProcessDisplayName);
    cas.setAttribute('InstType', instType);
    cas.setAttribute('SumCsign', sumCsign);
};
/**
 * 保存扩展属性设置
 *
 * @return
 */
SubProcessActivitySetting.prototype.updateExtra = function () {
    var GRIDNAME = "extraResult";
    // 设置扩展属性
    var doc = this.createXmlDocument();
    var actExtraParams = $(this.setting).find('ActivityExtraParameters')[0];
    if (actExtraParams == null) {
        actExtraParams = doc.createElement('ActivityExtraParameters');
        $(this.setting).find('Extras')[0].appendChild(actExtraParams);
    } else
        $(actExtraParams).empty();

    var block = extraResultGrid.getBlockData();
    var variable = null;
    if (block.getRows().length > 0)
        for (var i = 0; i < block.getRows().length; i++) {
            variable = doc.createElement('Variable');
            variable.setAttribute('Name', block.getCell(i, 'Name'));
            variable.setAttribute('Type', block.getCell(i, 'Type'));
            variable.setAttribute('Value', block.getCell(i, 'Value'));
            variable.setAttribute('Desc', block.getCell(i, 'Desc'));
            actExtraParams.appendChild(variable);
        }
};
/**
 * 保存子流程活动相关参数设置
 *
 * @return
 */
SubProcessActivitySetting.prototype.updateParametersOfSubProcessActSetting = function () {
    var GRIDNAME = "parametersResult";
    // 设置扩展属性
    var doc = this.createXmlDocument();
    var params = $(this.setting).find('Parameters')[0];
    if (params == null) {
        params = doc.createElement('Parameters');
        $(this.setting).find('Extras')[0].appendChild(params);
    } else
        $(params).empty();

    var block = parametersResultGrid.getBlockData();
    var parameter = null;
    if (block.getRows().length > 0)
        for (var i = 0; i < block.getRows().length; i++) {
            parameter = doc.createElement('Parameter');
            parameter.setAttribute('Type', block.getCell(i, 'Type'));
            parameter.setAttribute('Variable', block.getCell(i, 'Variable'));
            parameter.setAttribute('SubVariable', block.getCell(i, 'SubVariable'));
            params.appendChild(parameter);
        }
};